/**
 * 
 */
package tosp.search;

import tosp.HistoryMachine;
import tosp.JobSequence;
import tosp.job.Job;
import tosp.job.SimpleJob;

/**
 * @author atrox
 *
 */
public class ReverseSearch extends LocalSearchAdapter {

	public ReverseSearch(HistoryMachine m) {
		super(m);
	}

	@Override
	public JobSequence getNeighbor(JobSequence j, int i) {
		int from=i/j.getNumberOfJobs();
		int to=i%j.getNumberOfJobs();
		
		if (from>j.getNumberOfJobs()) return null;
		if (from==to) return new JobSequence(j);
		if (from>=to) return null;
		
		Job[] jobs=j.getJobsClone();
		for (;from<to;from++,to--) {
			jobs[from]=new SimpleJob(j.jobs[to]);
			jobs[to]=new SimpleJob(j.jobs[from]);
		}
		
		return new JobSequence(jobs);
	}
	
	@Override
	public int getNeighborSize(JobSequence j) {
		return j.getNumberOfJobs()*j.getNumberOfJobs();
	}

	@Override
	public JobSequence[] getNeighbors(JobSequence j) {
		return null;
	}
	
}
